package br.com.empresa.relatorio;

import java.io.File;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;

import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.view.JasperViewer;
import br.com.empresa.dao.FabricaConexao;

public class Relatorio {

	public static void abreRelatorio(String caminho) {
		Connection con = null;
		try {
			con = FabricaConexao.getConexao();

			Map parameters = new HashMap();
			File file = new File(caminho);
			file = file.getAbsoluteFile();
			String relatorio = file.getPath();

			JasperFillManager.fillReportToFile(relatorio, parameters, con);
			JasperPrint jasperPrint = JasperFillManager.fillReport(relatorio,
					parameters, con);

			JasperViewer viewer = new JasperViewer(jasperPrint, false);
			viewer.setVisible(true);

		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			try {
				con.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}
}
